using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_BABST
    {
        public DataRow Convert2QVW_BABST(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_BABST(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["SVDATE"] = " ".PadRight(8 ); 
         dwReturn["ARTST"] = " ".PadRight(1 ); 
         dwReturn["PART"] = " ".PadRight(20 ); 
         dwReturn["PVAR"] = " ".PadRight(2 ); 
         dwReturn["PCOLOR"] = " ".PadRight(10 ); 
         dwReturn["PDESS"] = " ".PadRight(10 ); 
         dwReturn["PDCWY"] = " ".PadRight(10 ); 
         dwReturn["PFINISH"] = " ".PadRight(10 ); 
         dwReturn["PSIZE"] = " ".PadRight(7 ); 
         dwReturn["LO"] = " ".PadRight(2 ); 
         dwReturn["LB"] = " ".PadRight(2 ); 
         dwReturn["MSTQTY"] = " ".PadRight(0 ); 
         dwReturn["MOVEIN"] = " ".PadRight(0 ); 
         dwReturn["MOVEOUT"] = " ".PadRight(0 ); 
         dwReturn["MADJUST"] = " ".PadRight(0 ); 
         dwReturn["STLENG"] = " ".PadRight(0 ); 
         dwReturn["AUFTYP"] = " ".PadRight(1 ); 
         dwReturn["KAUF"] = " ".PadRight(9 ); 
         dwReturn["PAUF"] = " ".PadRight(12 ); 
         dwReturn["PKRS"] = " ".PadRight(2 ); 
         dwReturn["PLFD"] = " ".PadRight(6 ); 
         dwReturn["PPOS"] = " ".PadRight(3 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_BABST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_BABST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_BABST(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_BABST(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_BABST(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_BABST(dwLocal);
        }
        public void InsertQVW_BABST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_BABST(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_BABST(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_BABST WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_BABST  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_BABST";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_BABST(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_BABST   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_BABST(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_BABST SET "
                    +"SVDATE= :SVDATE,"
                    +"ARTST= :ARTST,"
                    +"PART= :PART,"
                    +"PVAR= :PVAR,"
                    +"PCOLOR= :PCOLOR,"
                    +"PDESS= :PDESS,"
                    +"PDCWY= :PDCWY,"
                    +"PFINISH= :PFINISH,"
                    +"PSIZE= :PSIZE,"
                    +"LO= :LO,"
                    +"LB= :LB,"
                    +"MSTQTY= :MSTQTY,"
                    +"MOVEIN= :MOVEIN,"
                    +"MOVEOUT= :MOVEOUT,"
                    +"MADJUST= :MADJUST,"
                    +"STLENG= :STLENG,"
                    +"AUFTYP= :AUFTYP,"
                    +"KAUF= :KAUF,"
                    +"PAUF= :PAUF,"
                    +"PKRS= :PKRS,"
                    +"PLFD= :PLFD,"
                    +"PPOS= :PPOS,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("SVDATE", OracleType.NVarChar).Value = dwData["SVDATE"].ToString(); 
          or1.Parameters.Add("ARTST", OracleType.NVarChar).Value = dwData["ARTST"].ToString(); 
          or1.Parameters.Add("PART", OracleType.NVarChar).Value = dwData["PART"].ToString(); 
          or1.Parameters.Add("PVAR", OracleType.NVarChar).Value = dwData["PVAR"].ToString(); 
          or1.Parameters.Add("PCOLOR", OracleType.NVarChar).Value = dwData["PCOLOR"].ToString(); 
          or1.Parameters.Add("PDESS", OracleType.NVarChar).Value = dwData["PDESS"].ToString(); 
          or1.Parameters.Add("PDCWY", OracleType.NVarChar).Value = dwData["PDCWY"].ToString(); 
          or1.Parameters.Add("PFINISH", OracleType.NVarChar).Value = dwData["PFINISH"].ToString(); 
          or1.Parameters.Add("PSIZE", OracleType.NVarChar).Value = dwData["PSIZE"].ToString(); 
          or1.Parameters.Add("LO", OracleType.NVarChar).Value = dwData["LO"].ToString(); 
          or1.Parameters.Add("LB", OracleType.NVarChar).Value = dwData["LB"].ToString(); 
          or1.Parameters.Add("MSTQTY", OracleType.NVarChar).Value = dwData["MSTQTY"].ToString(); 
          or1.Parameters.Add("MOVEIN", OracleType.NVarChar).Value = dwData["MOVEIN"].ToString(); 
          or1.Parameters.Add("MOVEOUT", OracleType.NVarChar).Value = dwData["MOVEOUT"].ToString(); 
          or1.Parameters.Add("MADJUST", OracleType.NVarChar).Value = dwData["MADJUST"].ToString(); 
          or1.Parameters.Add("STLENG", OracleType.NVarChar).Value = dwData["STLENG"].ToString(); 
          or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString(); 
          or1.Parameters.Add("KAUF", OracleType.NVarChar).Value = dwData["KAUF"].ToString(); 
          or1.Parameters.Add("PAUF", OracleType.NVarChar).Value = dwData["PAUF"].ToString(); 
          or1.Parameters.Add("PKRS", OracleType.NVarChar).Value = dwData["PKRS"].ToString(); 
          or1.Parameters.Add("PLFD", OracleType.NVarChar).Value = dwData["PLFD"].ToString(); 
          or1.Parameters.Add("PPOS", OracleType.NVarChar).Value = dwData["PPOS"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
